import { ProColumnType, ProFormColumnsType } from "@ant-design/pro-components";
import { Button } from "antd";
import React from "react";

export type DataItem = {
  __disabled?: boolean;
  columnName: string;
  dataIndex: React.Key;
  type: any;
  fix: boolean;
  search: boolean;
};

export const columns: ProColumnType<{
  key1: string;
  key2: string;
  key3: string;
  key4: string;
}>[] = [
  {
    title: '列1',
    dataIndex: 'key1',
    search: false,
  },
  {
    title: '列2',
    dataIndex: 'key2',
    search: false,
  },
  {
    title: '列3',
    dataIndex: 'key3',
    search: false,
  },
  {
    title: '列4',
    dataIndex: 'key4',
    search: false,
  },
  {
    title: '操作',
    dataIndex: 'options',
    search: false,
    render(dom, entity, index, action, schema) {
      return (
        <>
          <Button type="link">编辑</Button>
          <Button type="link" style={{ color: 'red' }}>
            删除
          </Button>
        </>
      );
    },
  },
];

export const componentTypeEnum = {
  text: { text: '文本', status: 'text' },
  node: { text: '节点', status: 'node' },
  function: { text: '自定义方法', status: 'function' },
};

export const fixTypeEnum = {
  noFix: { text: '无', status: 'noFix' },
  left: { text: '左边', status: 'left' },
  right: { text: '右边', status: 'right' },
};

export const searchTypeEnum = {
  show: { text: '显示', status: 'show' },
  hidden: { text: '不显示', status: 'hidden' },
};

export const DataItemColumns: ProFormColumnsType<DataItem>[] = [
  {
    title: '列名',
    dataIndex: 'columnName',
    fieldProps: {
      placeholder: '请输入列名',
    },
    formItemProps: {
      rules: [
        {
          required: true,
          message: '此项为必填项',
        },
      ],
    },
  },
  {
    title: '索引',
    dataIndex: 'dataIndex',
    fieldProps: {
      placeholder: '请输入索引',
    },
    formItemProps: {
      rules: [
        {
          required: true,
          message: '此项为必填项',
        },
      ],
    },
  },
  {
    title: '类型',
    dataIndex: 'type',
    valueType: 'select',
    valueEnum: componentTypeEnum,
    fieldProps: {
      placeholder: '请输入列名',
    },
    formItemProps: {
      rules: [
        {
          required: true,
          message: '此项为必填项',
        },
      ],
    },
  },
  {
    title: '固定',
    dataIndex: 'fix',
    valueType: 'radio',
    valueEnum: fixTypeEnum,
    initialValue: 'noFix',
  },
  {
    title: '搜索',
    dataIndex: 'search',
    valueType: 'radio',
    valueEnum: searchTypeEnum,
    initialValue: 'hidden',
  },
];